<?php
/**
 * Abstract action controller
 * 
 * @author paq
 *
 */
abstract class Controller_Action extends Controller_Abstract
{
	/**
	 * Front controller wich dispatches to this controller
	 * 
	 * @var FrontController
	 */
	protected $_frontController;
	
	//protected $_templatesPath = '';
	
	public function __construct($name, Controller_Front $frontController)
	{
		// FIXME: check if not null
		parent::__construct($name);
		$this->_frontController = $frontController;
		//$this->setTemplatesPath();
	}
	
	/*protected function setTemplatesPath()
	{
		$tmp = explode($this->getName(), '_');
		$path = implode(DIRECTORY_SEPARATOR, $tmp);
		
		$this->_templatesPath = $path . DIRECTORY_SEPARATOR;
		var_dump($this->_templatesPath);
	}*/
	
	/**
	 * 
	 * @return Smarty
	 */
	protected function view()
	{
		return $this->_frontController->view();
	}
	
	protected function assign($variable, $value)
	{
		return $this->view()->assign($variable, $value);
	}
	
	protected function display($template)
	{
		//$this->view()->display($this->_templatesPath . $template);
		return $this->view()->display($template);
	}
	
	public function dispatch()
	{
		
	}
	
	/**
	 * Default controller action
	 * 
	 * @return void
	 */
	abstract public function indexAction();
	
/**
	 * Display ok info
	 * 
	 * @param string $msg	message to display
	 * @return 
	 */
	protected function ok($msg)
	{
		$this->view()->assign('ok_info', (string) $msg);
		return $this->view()->display('ok.tpl');
	}
	
	/**
	 * Display fail info
	 * 
	 * @param string $msg	message to display
	 * @return unknown_type
	 */
	protected function fail($msg)
	{
		$this->view()->assign('fail_info', (string) $msg);
		return $this->view()->display('fail.tpl');
	}
}